﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Gmantis.Controls
{
    public class SideRadiusConverter : IValueConverter
    {
        // Methods
        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            CornerRadius radius = new CornerRadius();
            if (value is CornerRadius)
            {
                radius = (CornerRadius)value;
            }
            else if (value is double)
            {
                radius = new CornerRadius((double)value);
            }
            List<string> list = new List<string>(((string)parameter).ToLower().Split(new char[] { '-', ' ' }));
            double num = 1.0;
            foreach (string str in list)
            {
                if (str.StartsWith("ratio:"))
                {
                    num = double.Parse(str.Substring(6), CultureInfo.InvariantCulture);
                }
            }
            return new CornerRadius(list.Contains("topleft") ? (radius.TopLeft * num) : 0.0, list.Contains("topright") ? (radius.TopRight * num) : 0.0, list.Contains("bottomright") ? (radius.BottomRight * num) : 0.0, list.Contains("bottomleft") ? (radius.BottomLeft * num) : 0.0);
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
